<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="账号" prop="UserName">
          <el-col :span="6">
<el-input v-model="ruleForm.UserName"></el-input>
          </el-col>
        
      </el-form-item>
       <el-form-item label="密码" prop="UserPwd">
            <el-col :span="6">
        <el-input type="password" v-model="ruleForm.UserPwd"></el-input>
         </el-col>
      </el-form-item>
      <el-form-item>
          <el-col :span="6">
        <el-button type="primary" @click="submitForm"
          >登录</el-button
        >
          <el-button type="primary" @click="registered"
          >注册</el-button
        >
        </el-col>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        ruleForm: {
          UserName:'',
          UserPwd:''
         
        },
        rules: {
          UserName: [
            { required: true, message: '请输入账号', trigger: 'blur' },
            { min: 3, message: '长度在2个字符以上', trigger: 'blur' }
          ],
          UserPwd: [
            { required: true, message: '请输入密码', trigger: 'blur' },
            { min: 3, message: '长度在2个字符以上', trigger: 'blur' }
          ],
        }
      };
    },
    methods: {
      submitForm() {
        this.$axios({
            url:'http://localhost:13443/api/Goods/Login/login',
            method:'post',
            data:this.ruleForm
        }).then(res=>{
            if(res.data!='')
            {
              sessionStorage.setItem("userid",res.data.UserId)
                alert('登录成功');
                this.$router.push('/ShopCar');
                return;
            }
            alert('登陆失败');
            return;
        })
      },
      registered(){
          this.$router.push('/registered');
      }
    }
  }
</script>